package com.ruoyi.project.beautyflower.advertisement.controller;

import java.util.List;

import com.ruoyi.project.beautyflower.BfUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.beautyflower.advertisement.domain.Advertisement;
import com.ruoyi.project.beautyflower.advertisement.service.IAdvertisementService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * 广告管理 信息操作处理
 * 
 * @author lxs
 * @date 2018-09-28
 */
@Controller
@RequestMapping("/beautyflower/advertisement")
public class AdvertisementController extends BaseController
{
    private String prefix = "beautyflower/advertisement";
	
	@Autowired
	private IAdvertisementService advertisementService;
	
	@RequiresPermissions("beautyflower:advertisement:view")
	@GetMapping()
	public String advertisement()
	{
	    return prefix + "/advertisement";
	}
	
	/**
	 * 查询广告管理列表
	 */
	@RequiresPermissions("beautyflower:advertisement:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Advertisement advertisement)
	{
		startPage();
        List<Advertisement> list = advertisementService.selectAdvertisementList(advertisement);
		return getDataTable(list);
	}
	
	/**
	 * 新增广告管理
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存广告管理
	 */
	@RequiresPermissions("beautyflower:advertisement:add")
	@Log(title = "广告管理", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Advertisement advertisement)
	{
		return toAjax(advertisementService.insertAdvertisement(advertisement));
	}

	/**
	 * 修改广告管理
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Advertisement advertisement = advertisementService.selectAdvertisementById(id);
		mmap.put("advertisement", advertisement);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存广告管理
	 */
	@RequiresPermissions("beautyflower:advertisement:edit")
	@Log(title = "广告管理", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Advertisement advertisement)
	{		
		return toAjax(advertisementService.updateAdvertisement(advertisement));
	}
	
	/**
	 * 删除广告管理
	 */
	@RequiresPermissions("beautyflower:advertisement:remove")
	@Log(title = "广告管理", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(advertisementService.deleteAdvertisementByIds(ids));
	}
	
}
